package com.school.admin.common.utils;

import cn.hutool.core.util.URLUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.school.admin.common.config.InjectionParameters;

/**
 * @author ：sunpx
 * @date ：Created in 2021/7/9 23:47
 * @description：RSA工具类
 * @modified By：
 * @ver//console.logon: $
 */
public class RsaUtils {


    private static String PRIVATE_KEY;

    private static String PUBLIC_KEY;

    private static String ACCESS_KEY_SECRET;

    public static void setConfigInfo(InjectionParameters info) {
        RsaUtils.PRIVATE_KEY = info.getPrivateKey();
        RsaUtils.PUBLIC_KEY = info.getPublicKey();
    }


    /**
     * 加密
     *
     * @param encryptionData
     * @return
     */
    public static String encryption(String encryptionData) {
        RSA rsa = new RSA(null, PUBLIC_KEY);
        String s = rsa.encryptBase64(encryptionData, KeyType.PublicKey);

        return s;

    }

    /**
     * 解密
     *
     * @param decryptData
     * @return
     */
    public static String decrypt(String decryptData) {
        RSA rsa = new RSA(PRIVATE_KEY, null);
        String s = rsa.decryptStr(decryptData, KeyType.PrivateKey);
        return URLUtil.decode(s);
    }

    public static void main(String[] args) {

    }

}
